package Hot100;

public class 跳跃游戏2 {
    public int jump(int[] nums) {
        int len = nums.length;
        if (len == 1) return 0;
        int preEnd = 0;
        int end = 0;
        int count = 0;
        for (int i = 0; i <= preEnd && preEnd < len - 1; i++) {
            if (i + nums[i] > end) end = i + nums[i];
            if (i == preEnd) {
                preEnd = end;
                count++;
            }
        }
        return count;
    }
}
